{
 "nbformat": 4,
 "nbformat_minor": 2,
 "metadata": {
  "language_info": {
   "name": "python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "version": "3.8.1-final"
  },
  "orig_nbformat": 2,
  "file_extension": ".py",
  "mimetype": "text/x-python",
  "name": "python",
  "npconvert_exporter": "python",
  "pygments_lexer": "ipython3",
  "version": 3,
  "kernelspec": {
   "name": "python38164bit602b710d192b46978661e492d4076dc8",
   "display_name": "Python 3.8.1 64-bit"
  }
 },
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "array([[0.09386948, 0.69805654, 0.85358633, 0.76603977, 0.0492718 ,\n        0.35280206, 0.57442081, 0.31887888, 0.82077153, 0.13347794],\n       [0.25541875, 0.59471836, 0.69103912, 0.79155731, 0.7509232 ,\n        0.06828974, 0.99854995, 0.03773034, 0.692084  , 0.79461878],\n       [0.92740178, 0.79814497, 0.50889575, 0.58125923, 0.50765761,\n        0.9839098 , 0.79533971, 0.73954422, 0.93987023, 0.24011399],\n       [0.19518552, 0.76341202, 0.41928194, 0.57079435, 0.56719392,\n        0.31413273, 0.44792118, 0.8968565 , 0.72673571, 0.16498087],\n       [0.2267932 , 0.396391  , 0.7826081 , 0.97393767, 0.81433393,\n        0.25958675, 0.80718967, 0.35589062, 0.26416927, 0.23704015],\n       [0.66774625, 0.71459738, 0.92365959, 0.42326711, 0.86152851,\n        0.83469537, 0.9024158 , 0.38666864, 0.49958415, 0.73336769],\n       [0.91120952, 0.92994809, 0.64780803, 0.5152665 , 0.0796078 ,\n        0.79634892, 0.47232544, 0.17363995, 0.67435919, 0.34271551],\n       [0.76344543, 0.11903819, 0.55301332, 0.27375294, 0.78800617,\n        0.06242802, 0.08808461, 0.15061301, 0.22905575, 0.42009304],\n       [0.09139865, 0.13767653, 0.35541378, 0.04322464, 0.04062239,\n        0.29577363, 0.51644854, 0.45165507, 0.75425039, 0.340717  ],\n       [0.0059667 , 0.77755853, 0.34847581, 0.53081872, 0.6828215 ,\n        0.69914982, 0.09470928, 0.40513252, 0.42003266, 0.03073065]])"
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "arr = np.random.rand(10,10)\n",
    "arr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "10"
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "m, n= arr.shape\n",
    "m"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "10"
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "800"
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "maped = []\n",
    "for i in range(m):\n",
    "    for j in range(n):\n",
    "        maped.append([i-1 , j-1 , arr[i][j]])\n",
    "        maped.append([i   , j-1 , arr[i][j]])\n",
    "        maped.append([i+1 , j-1 , arr[i][j]])\n",
    "        maped.append([i-1 , j , arr[i][j]])\n",
    "        maped.append([i+1 , j , arr[i][j]])\n",
    "        maped.append([i-1 , j+1 , arr[i][j]])\n",
    "        maped.append([i   , j+1 , arr[i][j]])\n",
    "        maped.append([i+1 , j+1 , arr[i][j]])\n",
    "len(maped)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": "array([[0.60330159, 0.69903228, 0.5885841 , 0.51259841, 0.62660937,\n        0.48386444, 0.73493242, 0.50312574],\n       [0.54441915, 0.65127591, 0.6009179 , 0.57850753, 0.55625101,\n        0.56086681, 0.69188595, 0.53658305],\n       [0.53183778, 0.67193039, 0.64439602, 0.62570151, 0.64789157,\n        0.64405625, 0.63458258, 0.47980823],\n       [0.5866605 , 0.64816763, 0.67033343, 0.60064205, 0.69367639,\n        0.54977095, 0.61644262, 0.50014054],\n       [0.68577047, 0.67297799, 0.69984376, 0.5871305 , 0.6241671 ,\n        0.51079317, 0.51869676, 0.39598138],\n       [0.66256471, 0.55656789, 0.56883043, 0.56941169, 0.51113646,\n        0.42436179, 0.42538832, 0.36696722],\n       [0.54873917, 0.37776609, 0.37787033, 0.2633781 , 0.38465219,\n        0.36490407, 0.41997737, 0.4135054 ],\n       [0.3767888 , 0.34794484, 0.44661558, 0.42199693, 0.37153379,\n        0.28094325, 0.33229085, 0.30600371]])"
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "out = np.zeros((m - 2, n - 2),dtype = np.float64   )\n",
    "for el in maped:\n",
    "    if el[0] > 0 and el[0] < m -1 and el[1] > 0 and el[1] < n-1:\n",
    "        out[el[0] - 1][el[1] -1] += el[2]\n",
    "out = out / 8\n",
    "out "
   ]
  }
 ]
}